{extend name="public/base" /}

{block name="content"}
<!--页面路径 和 页面标题-->
<div class="page-title">

    <div class="title-env">
        <h1 class="title">评论管理</h1>
        <p class="description">用户对视频的所有评论</p>
    </div>

    <div class="breadcrumb-env">

        <ol class="breadcrumb bc-1">
            <li>
                <a href="/admin"><i class="fa-home"></i>Home</a>
            </li>
            <li>
                <a href="/admin/video/index">视频管理</a>
            </li>
            <li class="active">
                <strong>评论管理</strong>
            </li>
        </ol>

    </div>

</div>

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">评论列表</font></font></h3>
                <div class="panel-options">
                    <button class="btn btn-icon btn-success pull-right" data-toggle="modal" data-target="#search-model">
                        <i class="fa-search"></i> 搜索
                    </button>
                </div>
            </div>
            <div class="panel-body panel-border">


                <section class="profile-env">



                            <div class="row">

                                <div class="col-sm-12">
                                    <!-- User timeline stories -->
                                    <section class="user-timeline-stories">


                                        {foreach $lists as $list}
                                        <!-- Timeline Story Type: Status -->
                                        <article class="timeline-story" id="art_{$list.id}">
                                            <!-- User info -->
                                            <header>
                                                <a href="#" class="user-img">
                                                    <img src="{$list.user_avatar}" alt="用户IMG" class="img-responsive img-circle">
                                                </a>

                                                <div class="user-details">
                                                    <a href="#">{$list.user_name}</a>  对  <strong> {$list.video_name} </strong>发表了评论。
                                                    <time>{$list.updated_at}</time>
                                                </div>
                                            </header>

                                            <div class="story-content">
                                                <!-- Story Content Wrapped inside Paragraph -->
                                                <p>{$list.content}</p>

                                                <!-- Story Options Links -->
                                                <div class="story-options-links">
                                                    <a href="#" data-toggle="modal" data-target="#video-zan-model" data-id="{$list.id}">
                                                        <i class="linecons-thumbs-up"></i>
                                                        点赞<span>（{$list.zan}）</span>
                                                    </a>

                                                    <a href="javascript:void(0)" data-id="{$list.id}" class="show_replies">
                                                        <i class="linecons-comment"></i>
                                                        评论<span>（{$list.replies_count}）</span>
                                                    </a>

                                                    <a href="javascript:void(0)" data-id="{$list.id}" class="deleted">
                                                        <i class="linecons-trash"></i>删除
                                                    </a>
                                                </div>

                                                {if !empty($list['replies_count'])}
                                                <!-- Story Comments -->
                                                <ul class="list-unstyled story-comments" id="replies_{$list.id}" style="display: none">
                                                    {foreach $list.lists as $replies}
                                                    <li id="replies_content_{$replies.id}">
                                                        <div class="story-comment">

                                                            <a href="#" class="comment-user-img">
                                                                <img src="{$replies.user_avatar}" alt="用户IMG" class="img-circle img-responsive">
                                                            </a>

                                                            <div class="story-comment-content" style="margin-right: 50px;">
                                                                <a href="#" class="story-comment-user-name">
                                                                    {$replies.user_name}
                                                                    <time>{$replies.created_at}</time>
                                                                </a>
                                                                <p>{$replies.content}</p>

                                                                <div class="story-options-links">
                                                                    <a href="#" data-toggle="modal" data-target="#zan-model" data-id="{$replies.id}">
                                                                        <i class="linecons-thumbs-up"></i>
                                                                        点赞<span>（{$replies.zan}）</span>
                                                                    </a>

                                                                    <a href="javascript:void(0)" data-id="{$replies.id}" class="show_son_replies">
                                                                        <i class="linecons-comment"></i>
                                                                        回复<span>（{$replies.replies_count}）</span>
                                                                    </a>

                                                                    <a href="javascript:void(0)" data-id="{$replies.id}" class="deleted-replies">
                                                                        <i class="linecons-trash"></i>删除
                                                                    </a>
                                                                </div>

                                                            </div>

                                                            {if !empty($replies.replies_count)}
                                                            <ul class="list-unstyled story-comments" id="replies_son_{$replies.id}" style="display: none;margin-left: 50px;">
                                                                {foreach $replies.replies_lists as $replies_list}
                                                                <li id="replies__son_content_{$replies_list.id}">
                                                                    <div class="story-comment">

                                                                        <a href="#" class="comment-user-img">
                                                                            <img src="{$replies_list.user_avatar}" alt="用户IMG" class="img-circle img-responsive">
                                                                        </a>

                                                                        <div class="story-comment-content" style="margin-right: 50px;">
                                                                            <a href="#" class="story-comment-user-name">
                                                                                {$replies_list.user_name}
                                                                                <time>{$replies_list.created_at}</time>
                                                                            </a>
                                                                            <p>{$replies_list.content}</p>

                                                                            <div class="story-options-links">
                                                                                <a href="#">
                                                                                    <i class="linecons-thumbs-up"></i>
                                                                                    点赞<span>（{$replies_list.zan}）</span>
                                                                                </a>

                                                                                <a href="javascript:void(0)" data-id="{$replies_list.id}" class="deleted-replies">
                                                                                    <i class="linecons-trash"></i>删除
                                                                                </a>
                                                                            </div>

                                                                        </div>


                                                                    </div>
                                                                </li>
                                                                {/foreach}
                                                            </ul>
                                                            {/if}



                                                        </div>
                                                    </li>
                                                    {/foreach}
                                                </ul>
                                                {/if}
                                            </div>
                                        </article>
                                        {/foreach}


                                    </section>

                                </div>

                            </div>
                            <div class="row">
                                <label class="col-md-6 control-label">共 {$lists->total()} 条评论</label>
                                <div class="col-md-6 text-right">
                                    <nav aria-label="Page navigation">
                                        {$lists->render()}
                                    </nav>
                                </div>
                            </div>

                        </section>

            </div>
        </div>
    </div>
</div>

{/block}

{block name="modal"}

<!--搜索模态框-->
<div class="modal fade" id="search-model" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
        <form method="get" class="form-horizontal" action="/admin/video/comment">
            <div class="modal-content">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">数据搜索</h4>
                </div>

                <div class="modal-body">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-6">
                                <input type="text" name="name" class="form-control" size="25" value="{$Think.get.name}">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="modal-footer">
                    <input type="submit" class="btn btn-info" value="确定搜索">
                </div>
            </div>
        </form>
    </div>
</div>

<div class="modal fade" id="video-zan-model" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
        <form method="post" id="video-zan" class="form-horizontal" action="/admin/video/comment_zan">
            <div class="modal-content">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">添加点赞数</h4>
                </div>

                <div class="modal-body">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-6">
                                <input type="number" name="zan" class="form-control">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="modal-footer">
                    <input type="hidden" name="id" id="comment_id">
                    <button type="button" class="btn btn-info" id="comment_zan">确定</button>
                </div>
            </div>
        </form>
    </div>
</div>


<div class="modal fade" id="zan-model" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
        <form method="post" id="zan" class="form-horizontal" action="/admin/video/replies_zan">
            <div class="modal-content">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">添加点赞数</h4>
                </div>

                <div class="modal-body">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-6">
                                <input type="number" name="zan" class="form-control">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="modal-footer">
                    <input type="hidden" name="id" id="replies_id">
                    <button type="button" class="btn btn-info" id="replies_zan">确定</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="js"}
<script>
    $('#video-zan-model').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var id = button.data('id');
        $('#comment_id').val(id)
    })

    $('#comment_zan').click(function () {
        var id = $(this).data('id');
        var targetUrl = $("#video-zan").attr("action");
        var data = $("#video-zan").serialize();
        $.ajax({
            type:'post',
            url:targetUrl,
            cache: false,
            data:data,
            dataType:'json',
            success:function(data){
                if(data.code == 0) {
                    success(data.message);
                    setTimeout("location.reload()",1000);
                }else{
                    error(data.message);
                }
            }
        })
    })

    $('#zan-model').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var id = button.data('id');
        $('#replies_id').val(id)
    })

    $('#replies_zan').click(function () {
        var id = $(this).data('id');
        var targetUrl = $("#zan").attr("action");
        var data = $("#zan").serialize();
        $.ajax({
            type:'post',
            url:targetUrl,
            cache: false,
            data:data,
            dataType:'json',
            success:function(data){
                if(data.code == 0) {
                    success(data.message);
                    setTimeout("location.reload()",1000);
                }else{
                    error(data.message);
                }
            }
        })
    })

    $('.show_replies').click(function () {
        var id = $(this).data('id');
        var div = $('#replies_'+id);
        div.toggle();
    })

    $('.show_son_replies').click(function () {
        var id = $(this).data('id');
        var div = $('#replies_son_'+id);
        div.toggle();
    })
    
    $('.deleted').click(function () {
        var id = $(this).data('id');
        $.ajax({
            url:'/admin/video/comment_delete',
            method: 'POST',
            dataType: 'json',
            data:{
                id:id,
            },
            success: function(res)
            {
                if(res.code == 0) {
                    var div = $('#art_'+id);
                    div.remove();
                }else{
                    error(res.message);
                }
            }
        })
    })

    $('.deleted-replies').click(function () {
        var id = $(this).data('id');
        $.ajax({
            url:'/admin/video/replies_delete',
            method: 'POST',
            dataType: 'json',
            data:{
                id:id,
            },
            success: function(res)
            {
                if(res.code == 0) {
                    var div = $('#replies_content_'+id);
                    div.remove();
                    var son_div = $('#replies__son_content_'+id);
                    son_div.remove();
                }else{
                    error(res.message);
                }
            }
        })
    })
</script>
{/block}
